package game.Player;

import game.Sprites.SpriteSheet;
import game.Weapons.Weapon_info;

import javafx.scene.paint.Color;

import java.util.ArrayList;
import java.util.List;

public class Team {
    private TeamController controller;
    private String name;
    private List<Weapon_info> weapons;
    private List<Player> players;
    private List<SpriteSheet> skins;
    private Color teamColor;

    public Team(String name, List<Weapon_info> weapons, List<SpriteSheet> skins, Color teamColor) {
        this.name = name;
        this.weapons = weapons;
        this.skins = skins;
        this.teamColor = teamColor;
        this.weapons = weapons;
        this.players = new ArrayList<>();

        this.controller = new TeamController(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Weapon_info> getWeapons() {
        return weapons;
    }

    public Weapon_info getInitialWeapon() {
        try {
            return (Weapon_info) weapons.get(0).clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    public Weapon_info getKinfe() {
        for(int i=0; i<weapons.size(); i++) {
            if (weapons.get(i).getName().contains("knife")) {
                return weapons.get(i);
            }
        }
        return null;
    }

    public void setWeapons(List<Weapon_info> weapons) {
        this.weapons = weapons;
    }

    public List<Player> getPlayers() {
        return players;
    }

    public void setPlayers(List<Player> players) {
        this.players = players;
    }

    public List<SpriteSheet> getSkins() {
        return skins;
    }

    public SpriteSheet getRandomSkin() {
        int max = skins.size();
        int rnd = (int) (Math.random() * max);// max not included

        return skins.get(rnd);
    }

    public void setSkins(List<SpriteSheet> skins) {
        this.skins = skins;
    }

    public Color getTeamColor() {
        return teamColor;
    }

    public void setTeamColor(Color teamColor) {
        this.teamColor = teamColor;
    }

    public void addPlayer(Player p) {
        this.players.add(p);
    }

    public void removePlayer(Player p) {
        this.players.remove(p);
    }

    public TeamController getController() {
        return this.controller;
    }

    public boolean isAnybodyElseDefusing(Player p1) {
        for (Player p2 : players) {
            if (p1 != p2 && p2.isDefusing()) return true;
        }
        return false;
    }

}
